{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# hvPlot.ohlc\n",
    "\n",
    "```{eval-rst}\n",
    ".. currentmodule:: hvplot\n",
    "\n",
    ".. automethod:: hvPlot.ohlc\n",
    "```\n",
    "\n",
    "## Backend-specific styling options\n",
    "\n",
    "```{eval-rst}\n",
    ".. backend-styling-options:: ohlc\n",
    "```\n",
    "\n",
    "## Examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example shows how to create a simple candlestick-style `ohlc` plot with a dummy dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\n",
    "    \"open\": [100, 101, 102],\n",
    "    \"high\": [104, 105, 110],\n",
    "    \"low\": [94, 97, 99],\n",
    "    \"close\": [101, 99, 103],\n",
    "}, index=pd.date_range(\"2024-01-01\", periods=3, freq=\"1D\"))\n",
    "\n",
    "df.hvplot.ohlc()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's use some a more realistic dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.apple_stocks(\"pandas\").set_index(\"date\").loc[\"2024-04\", :].reset_index()\n",
    "\n",
    "df.hvplot.ohlc(ylabel=\"Stock price\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also plot with the index as the date."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.apple_stocks(\"pandas\").set_index(\"date\").loc[\"2024-04\", :]\n",
    "\n",
    "df.hvplot.ohlc(ylabel=\"Stock price\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can control the plot styling with `neg_color`, `pos_color`, `line_color` and `bar_width`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.apple_stocks(\"pandas\").set_index(\"date\").loc[\"2024-04\", :]\n",
    "\n",
    "df.hvplot.ohlc(\n",
    "    neg_color='indianred', pos_color='chartreuse',\n",
    "    line_color='gray', bar_width=0.9,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default `ohlc` will assume the `index` OR the first datetime column should be mapped to the x-axis and the first four non-datetime columns correspond to the O (open), H (high), L (low) and C (close) components. The default call is therefore equivalent to:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.apple_stocks(\"pandas\").set_index(\"date\").loc[\"2024-04\", :].reset_index()\n",
    "\n",
    "df.hvplot.ohlc(x='date', y=['open', 'low', 'high', 'close'])"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
